#pragma once
#include "resource.h"

#include<vector>
#define dim(x) (sizeof(x)/sizeof(x[0]))



struct DecodeUnit{
	UINT message;
	LONG (*fun)(HWND,UINT,WPARAM,LPARAM);
};

struct MMData
{
public:
	int index;
	int flag;
	int x1, y1;
	int x2, y2;
	int acce;

};

struct SeatKeepAlive{
	char IP[20];
	int aliveTime;
};

#define MAX_ALIVETIME  10
#define MAX_AXIS_LONG  45
extern float axis1;
extern float axis2;
extern std::vector<MMData> gMMDataList;
extern std::vector<SeatKeepAlive> gSeatList;
extern int g_nDownlod;

extern int g_nDownloadN;
extern bool g_bConnect;
extern bool g_bOpen;
extern bool g_bPlay;
#define IP_HEAD		"192.168.1."

INT_PTR CALLBACK DlgPorc(HWND,UINT,WPARAM,LPARAM);

LONG OnInitDialog(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG DoCommand(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnClose(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);

bool ReadConfig();
VOID CALLBACK OnTimerProc(HWND hDlg,UINT message,UINT nIDEvent,DWORD lParam);
LONG OnBtnRunGameClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnSetZeroClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnStopClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnOpenFileClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnDownlodDataClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnPlayClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnLoadClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnSaveClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnConnectClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnToRightClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnToLeftClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
LONG OnBtnCheckAllClick(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);

DWORD WINAPI PositionThreadProc(LPVOID lp);
DWORD WINAPI TimerThreadProc(LPVOID lp);

void ConnectControlHost(HWND hDlg);
void SendControlReady(HWND hDlg);
void SendSeatStatus(HWND hDlg,int num,int status);
void SendSeatConnect(HWND hDlg,int num,int status);
void SendSeatConnectAll(HWND hDlg);
void SetSeatRunStatus(HWND hDlg,int num,int status);
void DeleteList(HWND hDlg,char *IP);
void DeleteRightList(HWND hDlg,char *IP);
void SetDownRate(HWND hDlg,char *IP,char *Rate);
void ZeroFinish(HWND hDlg);
void AddMotionCount(HWND hDlg);
void AddDownloadMotionCount(HWND hDlg);
void DelMotionCount(HWND hDlg);
void DelDownloadMotionCount(HWND hDlg);
void DelRunNum(HWND hDlg);
void SetRunNum(HWND hDlg,int num);
int GetRunNum(HWND hDlg);
void ClearAllReady(HWND hDlg);